import { BasicColumn, FormSchema } from '/@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import dayjs from 'dayjs';
const dates = ref();
export const columns: BasicColumn[] = [
  {
    title: '学生学号',
    dataIndex: 'stid',
    align: 'center',
    width: 120,
  },
  {
    title: '费用类型',
    dataIndex: 'type',
    align: 'center',
    width: 120,
  },
  {
    title: '一卡通对应id',
    dataIndex: 'oid',
    align: 'center',
    width: 120,
  },
  {
    title: '充值金额',
    dataIndex: 'money',
    align: 'center',
    width: 160,
  },
  {
    title: '房间号',
    dataIndex: 'room',
    align: 'center',
    width: 120,
  },
  {
    title: '充值时间',
    dataIndex: 'time',
    align: 'center',
    width: 180,
  },
  {
    title: '充值状态',
    dataIndex: 'state',
    align: 'center',
    customRender: ({ text }) => {
      return h(Tag, { color: text == 1 ? 'red' : 'green' }, () => (text == 1 ? '未付款' : '已付款'));
    },
    width: 120,
  },
  {
    title: '充电度数',
    dataIndex: 'quantity',
    align: 'center',
    width: 120,
  },
  {
    title: '端口号',
    dataIndex: 'port',
    align: 'center',
    width: 120,
  },
  // {
  //   title: 'recharges',
  //   dataIndex: 'recharges',
  //   align: 'center',
  //   width: 120,
  // },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'stid',
    label: '学生学号',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'rangeNumber',
    label: '充值金额',
    component: 'JRangeNumber',
    colProps: { span: 6 },
  },
  {
    field: 'room',
    label: '房间号',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'rtime',
    label: '充值时间',
    component: 'RangePicker',
    colProps: { span: 6 },
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['请选择开始日期时间', '请选择结束日期时间'],
      allowClear: false,
      disabledDate: (current) => {
        if (!dates.value || (dates.value as any).length === 0) {
          return false;
        }
        const tooLate = dates.value[0] && current.diff(dates.value[0], 'month') > 6;
        const tooEarly = dates.value[1] && dayjs(dates.value[1]).diff(current, 'month') > 6;
        return tooEarly || tooLate;
      },
      onCalendarChange: (val) => {
        dates.value = val;
      },
    },
    defaultValue: [
      dayjs().subtract(30, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
      dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss'),
    ],
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '学生学号',
    field: 'stid',
    component: 'Input',
  },
  {
    label: '费用类型',
    field: 'type',
    component: 'Input',
  },
  {
    label: '一卡通对应id',
    field: 'oid',
    component: 'Input',
  },
  {
    label: '充值金额',
    field: 'money',
    component: 'Input',
  },
  {
    label: '房间号',
    field: 'room',
    component: 'Input',
  },
  {
    label: '充值时间',
    field: 'time',
    component: 'DatePicker',
    componentProps: {
      //日期格式化，页面上显示的值
      format: 'YYYY-MM-DD HH:mm:ss',
      //返回值格式化（绑定值的格式）
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      //是否显示今天按钮
      showToday: true,
      showTime: true,
    },
  },
  {
    label: '充值状态',
    field: 'state',
    component: 'RadioButtonGroup',
    componentProps: {
      options: [
        { label: '未付款', value: 1 },
        { label: '已付款', value: 2 },
      ],
    },
  },
  {
    label: '充值度数',
    field: 'quantity',
    component: 'Input',
  },
  {
    label: '端口号',
    field: 'port',
    component: 'Input',
  },
  {
    label: 'recharges',
    field: 'recharges',
    component: 'Input',
  },
];
